﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Users : System.Web.UI.Page {

    #region Methods ///////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Binds the users.
    /// </summary>
    private void BindUsers() {
        rptUsers.DataSource = Membership.GetAllUsers();
        rptUsers.DataBind();
    }

    /// <summary>
    /// Handles the command.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param>
    protected void HandleCommand(object sender, CommandEventArgs e) {

        string username;
        switch (e.CommandName) {
            case "Create":
                break;
            case "Delete":
                username = e.CommandArgument as string;
                if (!string.IsNullOrEmpty(username)) {
                    Membership.DeleteUser(username);
                }
                this.BindUsers();
                break;
        }
    }

    /// <summary>
    /// Handles the roles list load.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void HandleRolesListLoad(object sender, EventArgs e) {

        CheckBoxList cbl = sender as CheckBoxList;
        if (cbl != null) {
            cbl.DataSource = System.Web.Security.Roles.GetAllRoles();
            cbl.DataBind();
        }
    }

    /// <summary>
    /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
    /// </summary>
    /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
    protected override void OnLoad(EventArgs e) {
        base.OnLoad(e);

        if (!IsPostBack) this.BindUsers();
    }
    #endregion
}
